/**
 * @author casazaft
 */
/**
 * @author casazaft
 */
Package("xclab.mvc.patterns.facade").Class("Facade", {
        Facade: function(){
 this.Super.constructor();            this.controller = null;
            this.view = null;
            this.model = null;
            this.initializeFacade();
        },
        Methods: {
            initializeFacade: function(){
                this.initializeModel();
                this.initializeController();
                this.initializeView();
                
            },
            initializeModel: function(){
                if (this.model != null) 
                    return;
                
                var Model = Import("xclab.mvc.core.Model");
                this.model = Model.getInstance();
            },
            initializeController: function(){
                if (this.controller != null) 
                    return;
                var Controller = Import("xclab.mvc.core.Controller");
                
                this.controller = Controller.getInstance();
            },
            initializeView: function(){
                if (this.view != null) 
                    return;
                var View = Import("xclab.mvc.core.View");
                this.view = View.getInstance();
            },
            registerCommand: function(notificationName, commandClassRef){
            
                this.controller.registerCommand(notificationName, commandClassRef);
            },
            removeCommand: function(notificationName){
                return this.controller.removeCommand(notificationName);
            },
            hasCommand: function(notificationName){
                return this.controller.hasCommand(notificationName);
            },
            registerProxy: function(proxy){
                this.model.registerProxy(proxy);
            },
            retrieveProxy: function(proxy){
                return this.model.retrieveProxy(proxy);
            },
            removeProxy: function(proxy){
                return this.model.removeProxy(proxy);
            },
            hasProxy: function(proxy){
                return this.model.hasProxy(proxy);
            },
            registerMediator: function(mediator){
                this.view.registerMediator(mediator);
            },
            retrieveMediator: function(mediator){
                return this.view.retrieveMediator(mediator);
            },
            removeMediator: function(mediator){
                return this.view.removeMeidator(mediator);
            },
            hasMediator: function(mediator){
                return this.view.hasMediator(mediator);
            },
            notifyObservers: function(notification){
                if (this.view != null) {
                    this.view.notifyObservers(notification);
                    
                }
            },
            sendNotification: function(name, body, type){
                var Notification = Import("xclab.mvc.patterns.observer.Notification");
                this.notifyObservers(new Notification(name, body, type));
            }
        
        
        },
        Extends: j2j.patterns.Singleton
    })




